﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

using Qianwei.Model;
using Qianwei.Biz;
using Qianwei.Common.Extension;

namespace Qianwei.Web
{
    public partial class ExternalReporting : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetTitle();
                SetNews();
            }
        }

        private void SetTitle()
        {
            string url = System.IO.Path.GetFileName(Request.Url.AbsolutePath);
            IList<page_info> pageinfo = PageInfoManager.Instance.QueryPageInfo(string.Format("Page_Url='{0}'", url));
            if (pageinfo == null || pageinfo.Count == 0)
            {
                lcontenttitle.Text = "未知标题";
                return;
            }
            page_info pagenew = pageinfo.First();
            lcontenttitle.Text = pagenew.Page_Title;
            //lcontent.Text = pagenew.Page_Content;
        }

        private void SetNews()
        {
            StringBuilder strnews = new StringBuilder();
            IList<news_center> news = NewsCenterManager.Instance.QueryNewsCenter(10, "New_Type=" + (int)AppEnum.NewType.ExterReport, "New_Center_Id DESC");
            var newspager = Common.DataPaging<news_center>.GetDataSource(AspNetPager, news);

            strnews.Append("<div class=\"main_content\">");
            foreach (var nc in newspager)
            {
                strnews.Append("<div class=\"newslist\">");
                strnews.Append("<div class=\"title\">");
                strnews.AppendFormat("<span class=\"time\">[{0}]</span> <a href=\"/News.aspx?nid={1}\">{2}</a>",
                    nc.Create_Time.ToString("yyyy-MM-dd"), nc.New_Center_Id, nc.New_Title);
                strnews.Append("</div>");
                strnews.Append("<div class=\"intor\"></div>");
                strnews.AppendFormat("<div class=\"other\"><a href=\"/News.aspx?nid={0}\">阅读全文</a></div>",
                    nc.New_Center_Id);
                strnews.Append("</div>");
            }
            strnews.Append("</div>");

            lcontent.Text = strnews.ToString();

        }

        #region Event
        protected void AspNetPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager.CurrentPageIndex = e.NewPageIndex;
            SetNews();
        }
        #endregion
    }
}